﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AnimationLesson01
{
    /// <summary>
    /// LinnerAnimationWindow.xaml 的交互逻辑
    /// 简单线性动画示例窗口
    /// </summary>
    public partial class LinnerAnimationWindow : Window
    {
        public LinnerAnimationWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("===btn_Click===");

            DoubleAnimation widthAnimation = new DoubleAnimation();
            widthAnimation.Duration = new TimeSpan(0, 0, 5);
            widthAnimation.From = 100;
            widthAnimation.To = 300;
            //widthAnimation.RepeatBehavior = RepeatBehavior.Forever;

            this.border.BeginAnimation(WidthProperty, widthAnimation);


            DoubleAnimation heightAnimation = new DoubleAnimation();
            heightAnimation.Duration = new TimeSpan(0, 0, 3);
            heightAnimation.From = 50;
            heightAnimation.To = 350;
            //widthAnimation.RepeatBehavior = RepeatBehavior.Forever;

            //this.border.BeginAnimation(HeightProperty, heightAnimation);

            // 如果多个动画需要同时执行，可以将相应是对象放到一个StoryBoard
            // 多条故事线  同步推进
            // Storyboard

            Storyboard sb = new Storyboard();
            sb.Children.Add(widthAnimation);
            sb.Children.Add(heightAnimation);

            // 这里指定相关的动画对象，与哪个页面对象相关
            // 
            Storyboard.SetTarget(widthAnimation, this.border);
            Storyboard.SetTargetProperty(widthAnimation, new PropertyPath("Width"));

            Storyboard.SetTarget(heightAnimation, this.border);
            Storyboard.SetTargetProperty(heightAnimation, new PropertyPath("Height"));

            sb.Begin();
        }
    }
}
